<?php

namespace app\common\model\country;

use think\Model;

/**
 * CoinConf
 */
class CoinConf extends Model
{
    // 表名
    protected $name = 'country_coin_conf';

    // 自动写入时间戳字段
    protected $autoWriteTimestamp = false;

    // 追加属性
    protected $append = [
        'countrysTable',
    ];


    public function getCountrysTableAttr($value, $row): array
    {
        return [
            'alias' => \app\common\model\country\Area::whereIn('abbr', $row['countrys'])->column('alias'),
        ];
    }

    public function getCountrysAttr($value): array
    {
        if ($value === '' || $value === null) return [];
        if (!is_array($value)) {
            return explode(',', $value);
        }
        return $value;
    }

    public function setCountrysAttr($value): string
    {
        return is_array($value) ? implode(',', $value) : $value;
    }

    public function getProductAttr($value): float
    {
        return (float)$value;
    }
}